package ModelLayer;

import java.util.Date;
import java.util.ArrayList;

public class SalesOrder 
{
	private int orderID;
	private int orderNr;
	private Date date;
	private String deliveryStatus;
	private Date deliveryDate;
	private double totalPrice;
	private Date returnDate;
	private String orderType;
	private Invoice invoice;
	private Customer customer;
	private ArrayList<PartOrder> partorders;
	
	public SalesOrder()
	{
		
	}
	
	public SalesOrder(int orderID)
	{
		this.orderID = orderID;
	}
	
	public SalesOrder(int orderNr, Date date, String deliveryStatus, Date deliveryDate, double totalPrice, Date returnDate, String orderType, Customer customer, Invoice invoice)
	{
		this.orderNr = orderNr;
		this.date = date;
		this.deliveryStatus = deliveryStatus;
		this.deliveryDate = deliveryDate;
		this.totalPrice = totalPrice;
		this.returnDate = returnDate;
		this.orderType = orderType;
		this.invoice = invoice;
		this.customer = customer;
		partorders = new ArrayList<PartOrder>();
	}
	
	public void setOrderNr(int newOrderNr)
	{
		orderNr = newOrderNr;
	}
	public void setDate(Date newDate)
	{
		date = newDate;
	}
	public void setDeliveryStatus(String newDeliveryStatus)
	{
		 deliveryStatus = newDeliveryStatus;
	}
	public void setDeliveryDate(Date newDeliveryDate)
	{
		deliveryDate = newDeliveryDate;
	}
	public void setTotalPrice(double newTotalPrice)
	{
		totalPrice = newTotalPrice;
	}
	public void setReturnDate(Date newReturnDate)
    {
    	this.returnDate = newReturnDate;
    }
	public void setOrderType(String newOrderType)
    {
    	this.orderType = newOrderType;
    }
	public void setCustomer(Customer newCustomer)
    {
    	this.customer = newCustomer;
    }
	public void setInvoice(Invoice newInvoice)
    {
    	this.invoice = newInvoice;
    }
	
	public int getOrderNr()
	{
		return orderNr;
	}
	public Date getDate()
	{
		return date;
	}
	public String getDeliveryStatus()
	{
		return deliveryStatus;
	}
	public Date getDeliveryDate()
	{
		return deliveryDate;
	}
	public Double getTotalPrice()
	{
		return totalPrice;
	}
	public Date getReturnDate()
    {
    	return returnDate;
    }
	public String getOrderType()
    {
    	return orderType;
    }
	public Customer getCustomer()
    {
    	return customer;
    }
	public Invoice getInvoice()
    {
    	return invoice;
    }
	
	public void addPartOrder(PartOrder partOrder)
    {
    	this.partorders.add(partOrder);
    }

    public PartOrder getPartOrder(int part)
    {
    	if (partorders.size() <= part)
    	{
    		return partorders.get(part);
    	}
    	else
    	{
    		return null;
    	}
    }
//	public double calculateTotal()
//    {
//        String discountType = discount.getDiscountType();
//        double discountPrice = discount.getDiscountPrice();
//        
//        for(int index = 0; partorders.size() > index; index++)
//        {
//            PartOrder partOrder = partorders.get(index);
//        }
//        
//        boolean done = false;
//        while(!done)
//        {
//        	if(percent <= 20)
//            {
//            	int subtotal = 0;
//            	
//            	for(int index = 0; partOrders.size() > index; index++)  // regner forkert 
//                {
//                    PartOrder partOrder = partOrders.get(index);
//                    subtotal += partOrder.getSubTotal();
//                }
//            	
//            	int discount = (subtotal * percent / 100);
//            	
//            	totalPrice = subtotal - discount;
//            	done = true;
//            }
//            else
//            {
//            	percent = 20;
//            }
//        }
//        return totalPrice;
//    }
}
